package com.lkx.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lkx.dao.ApiSubjectMapper;
import com.lkx.dao.ApiTypeMapper;
import com.lkx.domain.ApiSubject;
import com.lkx.domain.ApiType;
import com.lkx.service.ApiTypeService;
import com.lkx.util.PageModule;

@Service
public class ApiTypeServiceImpl implements ApiTypeService {

    private Logger logger = LoggerFactory.getLogger(ApiSubjectServiceImpl.class);
    @Autowired
    private ApiTypeMapper apiTypeMapper;
    @Override
    public int add(ApiType model) {
        int num = 0;
        try {
            num = apiTypeMapper.insert(model);
        } catch (Exception e) {
            logger.error("ApiSubjectServiceImpl add : " + e.getMessage());
        }
        return num;
    }

    @Override
    public PageModule list(Long subjectId, Long userid) {

        PageModule module = new PageModule();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("subjectId", subjectId);
            map.put("userId", userid);
            List<ApiType> list = new ArrayList<ApiType>();
            list = apiTypeMapper.selectByUserIdAndSubjectId(map);
            if (list != null && list.size() > 0) {
                module.setStatus(true);
                module.setList(list);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return module;
    }

}
